package com.jack.blog.utils;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Properties工具类
 */
public final class PropUtil {

    /**
     * 根据Properties配置文件名获取Prop
     * @param configName
     * @return
     * @throws Exception
     */
    public static Properties getConfigProperties(String configName)throws Exception{
        if (!configName.endsWith(".properties"))
            throw new IllegalArgumentException("not a properties file!");
        Properties properties=new Properties();
        //GetResource方法默认从根目录下读取
        InputStream in =Thread.currentThread().getContextClassLoader().getResourceAsStream(configName);
        if(in==null) {
            throw new FileNotFoundException(configName+" file is not found!");
        }
        properties.load(in);
        return properties;
    }
}
